import pymongo
from RSpider import settings
# from RSpider.insertDataDAO import insertData
from RSpider.statscol.graphite import RedisCache
class FucaiPipeling(object):
    def __init__(self):
        client = pymongo.MongoClient()
        db = client[settings.MONGODB_DBNAME]
        self.post = db[settings.MONGODB_DOCNAME]

    def process_item(self, item, spider):
        import time
        s = time.time()
        rediscol = RedisCache()

        if rediscol.set_data("urlSet",item.get("c_Url")) == 1:
            #insertData(item)#mysql
            datajson = eval(str(item))
            self.post.insert(datajson)
            e = time.time()
            print(e-s)
            return item


if __name__ == '__main__':
    fuca = FucaiPipeling()
    fuca.process_item({'data':'data'})


# class InsertRedis():
#     def __init__(self):
#         self.Redis = RedisOpera('insert')